package com.wngbms.demo.controller;

import com.wngbms.demo.annotation.DataBase;
import com.wngbms.demo.entity.MmallOrder;
import com.wngbms.demo.mapper.MmallOrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

import static com.wngbms.demo.config.DatabaseContextHolder.SLAVE;

@Slf4j
@RestController
public class TestController {

    @Autowired
    MmallOrderMapper mapper;

    @GetMapping("/insert")
    public String insert() {
        MmallOrder mmallOrder = new MmallOrder();
        mmallOrder.setOrderNo(99L);
        mmallOrder.setUserId(69);
        mmallOrder.setShippingId(23);
        mmallOrder.setPayment(new BigDecimal("234.2"));
        mmallOrder.setPaymentType(2);
        mmallOrder.setPostage(32);
        mmallOrder.setStatus(40);
        mmallOrder.setPaymentTime(new Date());
        mmallOrder.setSendTime(new Date());
        mmallOrder.setEndTime(new Date());

        mapper.insert(mmallOrder);

        return "success";
    }

    @GetMapping("/get/{id}")
    @DataBase(SLAVE)
    public MmallOrder get(@PathVariable Integer id) {
        MmallOrder mmallOrder = mapper.selectByPrimaryKey(id);
        return mmallOrder;
    }

}
